package inits

import (
	"fmt"
	"github.com/streadway/amqp"
	"house/config"
	"house/global"
	"log"
)

func InitRabbitMq() {
	data := config.ConfigData.Rabbit
	//获取connection
	conn, err := amqp.Dial(fmt.Sprintf("amqp://%s:%s@%s:%d/%s", data.Username, data.Password, data.Host, data.Port, data.Vhost))
	if err != nil {
		panic("Failed to connect to RabbitMQ")
	}
	//获取channel
	global.MQ, err = conn.Channel()

	if err != nil {
		panic("Failed to open a channel")
	}

	log.Println("Connected to RabbitMQ")

}
